// pages/goods/search/index.js
var app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        parameter: {
            'navbar': '1',
            'return': '1',
            'title': '信用保证金流水',
            'color': true,
            'class': false
        },
        navH: app.globalData.navHeight,
        executorUserId: "",
        preposeList: wx.getStorageSync('preposeList') || [],
        store: null,
        inputValue: "",
        goodsList: [],
        showHistory: true,
        isSearchList: true,
    },
/**
     * 生命周期函数--监听页面加载
     */
    onShow: function (options) {
        var that = this;
        that.setData({
            preposeList: wx.getStorageSync('preposeList') || [],
        })
    },
    // 读取输入值
    inputText: function (e) {
        this.setData({
            inputValue: e.detail.value
        })
    },
    //把用户输入的值保存在inputValue中
    doSearch: function (e) {
        var inputValue = this.data.inputValue;
        var preposeList = this.data.preposeList || [];
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        if (inputValue) {
            preposeList.push(inputValue);
            wx.setStorageSync('preposeList', preposeList);
        }
        prevPage.setData({
            pageNum: 1,
            goodsName: '',
            goodsName: inputValue,
            placeholder: inputValue
        })
        prevPage.flowData()
        wx.navigateBack({
            delta: 1,
        })
    },
    //历史查询
    historySearch: function (e) {
        var inputValue =  e.currentTarget.dataset.item;
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        console.log(prevPage)
        prevPage.setData({
            pageNum: 1,
            goodsName: '',
            goodsName: inputValue,
            placeholder: inputValue
        })
        prevPage.flowData()
        wx.navigateBack({
            delta: 1,
        })
    },
    //清空搜索历史
    clearHistory: function () {
        wx.removeStorageSync('preposeList')
        this.setData({
            preposeList: []
        })
    },
    // 返回上一页
    back: function (e) {
        let pages = getCurrentPages();
        let prevPage = pages[pages.length - 2];
        prevPage.setData({
            goodsName: '',
            placeholder: ''
        })
        wx.navigateBack({
            delta: 1,
        })
    }
})